package com.sylli.oeuf.server.exception;

public class BasedException extends Exception {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4607992151167351067L;

	private ExceptionCause _ec;
	
	public BasedException() {
		super();
		_ec = null;
	}
	
	public BasedException(String m) {
		super(m);
		_ec = null;
	}
	
	public BasedException(ExceptionCause ec) {
		super(ec.toString());
		_ec = ec;
	}
	
	public BasedException(ExceptionCause ec, String m) {
		super(ec.toString() + " (" + m + ")");
		_ec = ec;
	}
	
	public BasedException(Throwable t) {
		super(t);
		_ec = null;
	}
	
	public BasedException(String m, Throwable t) {
		super(m,t);
		_ec = null;
	}
	
	public BasedException(ExceptionCause ec, String m, Throwable t) {
		super(ec.toString() + " (" + m + ") "  + t.getMessage(), t);
		_ec = ec;
	}
	
	public BasedException(ExceptionCause ec, Throwable t) {
		super(ec.toString() + t.getMessage(), t);
		_ec = ec;
	}
	
	public boolean checkCause(ExceptionCause ec) {
		return (_ec == null)?false:_ec.equals(ec);
	}
	
	
	
	/* utils */
	public static void createException(ExceptionCause ec) throws BasedException {
		throw new BasedException(ec.toString());
	}
}
